import os
import yaml

#读取  f就是文件对象

def read_config(key):
    try:
        with open(os.getcwd()+'/common/config.yaml',mode='r',encoding='utf-8')as f:
            value = yaml.load(f,yaml.FullLoader)
            return value[key]
    except Exception as e:
        return e
#写入

def write_config(data):
    try:
        with open(os.getcwd() + '/common/config.yaml', mode='a', encoding='utf-8') as f:
            yaml.dump(data, stream=f, allow_unicode=True)
    except Exception as e:
        return e

#清空

def clear_config():
    try:
        with open(os.getcwd() + '/common/config.yaml', mode='w', encoding='utf-8') as f:
            f.truncate()
    except Exception as e:
        return e
